package com.ryan.demand.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ryan.demand.entity.Demand;
import com.ryan.demand.mapper.DemandMapper;
import com.ryan.demand.service.DemandService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 定制需求 服务实现类
 * </p>
 *
 * @author ryan
 * @since 2020-07-30
 */
@Service
public class DemandServiceImpl extends ServiceImpl<DemandMapper, Demand> implements DemandService {

    /**
     * 分页+条件查询
     * @param pageIndex
     * @param pageSize
     * @param mobile
     * @return
     */
    @Override
    public Map<String, Object> queryPage(long pageIndex, long pageSize, String mobile) {
        QueryWrapper<Demand> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("gmt_create");
        if(!StringUtils.isEmpty(mobile)){
            wrapper.like("phone_number", mobile);
        }
        Page<Demand> demandPage = new Page<>(pageIndex, pageSize);
        baseMapper.selectPage(demandPage, wrapper);
        Map<String,Object> map = new HashMap<>();
        List<Demand> records = demandPage.getRecords();
        long total = demandPage.getTotal();
        map.put("list", records);
        map.put("total", total);
        return map;
    }
}
